<template>
  <div class="to-do-main">
    <div v-if="toDoList.length > 0">
      <ul>
        <li v-for="(item, index) in toDoList" :key="item.id">
          {{ index + 1 }} - {{ item.name }}
          <a v-on:click.prevent="del(item.id)">删除</a>
        </li>
      </ul>
    </div>
    <div v-else>暂无数据</div>
  </div>
</template>

<script>
export default {
  name: "ToDoMain",
  props: {
    toDoList: {
      type: Array,
      required: false,
    },
  },
  data() {
    return {};
  },
  methods: {
    del(id) {
      // 通知父组件删除数据
      this.$emit("deleThing", id);
    },
  },
};
</script>

<style scoped>
.to-do-main {
  width: 500px;
  height: auto;
}
</style>